import xml.etree.ElementTree as ET
import os

class XMLTools:
    path=''

    def Creat_xml(self):
        root=ET.Element('RL_Python_Config')

        soconf=ET.SubElement(root,'Socket_Config')
        IP_address=ET.SubElement(soconf,'IP_Address')
        Port_add=ET.SubElement(soconf,'Port_Address')
        IP_address.text='127.0.0.1'
        Port_add.text='51423'

        SocServerConf = ET.SubElement(root, 'Socket_Server_Config')
        Port_server = ET.SubElement(SocServerConf, 'Port_Address')
        Port_server.text = '51423'

        RLconf = ET.SubElement(root, 'RL_Config')

        DataBaseConf=ET.SubElement(root,'Mysql_Config')
        username=ET.SubElement(DataBaseConf,'username')
        password = ET.SubElement(DataBaseConf, 'password')
        host = ET.SubElement(DataBaseConf, 'host')

        tree=ET.ElementTree(root)
        tree.write('Config.xml','utf-8',method='xml',short_empty_elements=False,xml_declaration=True)


    def Read_xml(self,filepath,nodename):
        tree=ET.parse(filepath)
        return tree.findtext(nodename)

    def Xml_Exist(self,path):
        if os.path.exists(path):
            return True
        else:
            return False

    def findfile(self,filename):
        pass




